import { Dialog, Message } from '../modal'


export function useConfirm(api: (...args: any) => Promise<any>, text: string, callback: any) {
  return async (...args: any): Promise<void> => {
    await Dialog.confirm({
      content: `确认要${text}吗？`,
      onOk: async (): Promise<void> => {
        const result = await api(...args)
        if (result !== false) {
          Message.success(`${text}成功`)
          await callback()
        }
      },
      title: text,
    }).catch(_ => {})
  }
}
